#!/bin/bash
# This shell script recreates a test database and populates it with objects and
# initial data for grop.  Hack it to work right for your install after testing.
# Run it as the admin user

PGPATH=/usr/local/pgsql/bin/
PSQL="${PGPATH}psql -p 5433"
CREATEDB="${PGPATH}createdb -p 5433"
DBNAME=grop
SCHEMANAME=test

# Create the database. This errors out if it exists which is fine.
$CREATEDB $DBNAME 2>errors

echo "
drop schema $SCHEMANAME cascade;
\set ON_ERROR_STOP
create schema $SCHEMANAME;
grant all on schema $SCHEMANAME to $SCHEMANAME ;
set session authorization $SCHEMANAME ;
set search_path=${SCHEMANAME},public;
\i tables.sql
\i defaultdata.sql
\i constraints.sql
\i views.sql
\i functions.sql
-- There is a circular dependency between views and functions so we have to do it again.
\i views.sql
\i indexes.sql
\i sequences.sql
\i triggers.sql
\i comments.sql
" | $PSQL $DBNAME 2>>errors

grep "ERROR" errors
